package cn.appsys.controller.developer;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.appsys.pojo.DevUser;
import cn.appsys.service.developer.DevUserService;


@Controller
@RequestMapping(value="/dev")
public class DevLoginController {
	private Logger logger = Logger.getLogger(DevLoginController.class);
	@Resource
	private DevUserService devUserService;
	@RequestMapping(value="/login")
	public String login(){
		
		return "login";
	}
	
	
@RequestMapping(value="/dologin",method=RequestMethod.POST)

public String dologin(@RequestParam String devCode,@RequestParam String devPassword ,
		HttpServletRequest request,HttpSession session
		
		) throws Exception{
	DevUser devUser = devUserService.getLoginUser(devCode);

	if (devUser==null) {
		request.setAttribute("error", "用户名或密码不能为空");
		return "login";
	} else {
		if (devUser.getDevPassword().equals(devPassword)) {
			
			session.setAttribute("username", devCode);
			return "main";
		}else {
			request.setAttribute("error", "用户名或密码不正确");
			return "login";
		}
	}
}
@RequestMapping(value="/loginout")
public String logout(HttpSession session){
	//清除session
	session.removeAttribute("username");
	return "login";
}
























}
